﻿@{
    ViewBag.Title = "通知公告";
}
<div class="table-wraper">
    <div class="table-header">
        <h3 class="table-title">
            公告列表<small>&nbsp;&nbsp;<a href="/Admin/Notice/Create" role="button" id="btnAdd" class="btn btn-primary btn-sm">添加公告</a></small>
        </h3>
        <div class="form-inline" style="margin: 0.6em 0">
            <div class="form-group">
                <input type="search" value="" id="title" placeholder="通知公告标题" class="form-control" />
            </div>
            <button id="btnSearch" type="button" class="btn btn-success">搜索</button>
        </div>
    </div>
    <div class="table-body" id="div_main"></div>
</div>
@section scripts{
    <script>
        var pageSize = 10, pageIndex = 1;

        //加载数据
        function loadData(pIndex) {
            if (!pIndex) {
                pageIndex = 1;
            } else {
                pageIndex = pIndex;
            }
            $("#div_main").html('<br /><img src="/images/loading.gif" /> 正在玩命加载中，请稍后...');
            $.ajax({
                url: "/Admin/Notice/List",
                data: {
                    "PageIndex": pageIndex,
                    "PageSize": pageSize,
                    "SearchItem1": $("#title").val()
                },
                success: function(data, status) {
                    if (status == "success") {
                        $("#div_main").html(data);
                    } else {
                        $("#div_main").html('');
                        layer.msg('数据加载异常，请稍后重试！');
                    }
                }
            });
        }

        function DeleteNotice(noticeId) {
            if (!noticeId) return;

            layer.confirm('确定要删除通知吗？',
                { title: '警告' },
                function(index) {
                    $.post('@Url.Action("Delete")',
                        { 'noticeId': noticeId },
                        function(data) {
                            if (!data) {
                                $(".tr_" + noticeId).remove();
                                layer.msg('删除成功');
                                layer.close(index);

                            } else {
                                layer.msg(data);
                            }
                        });
                });
        }

        //搜索
        $("#btnSearch").on("click",
            function() {
                loadData();
            });

        $(function() {
            loadData();
        });
    </script>
}